package edu.kit.los.lookup;


import java.util.LinkedList;
import java.util.List;

import javax.naming.directory.SearchResult;

import com.evdb.javaapi.APIConfiguration;
import com.evdb.javaapi.EVDBAPIException;
import com.evdb.javaapi.EVDBRuntimeException;
import com.evdb.javaapi.data.request.EventSearchRequest;
import com.evdb.javaapi.operations.EventOperations;

import edu.kit.los.event.StandartEvent;

/**
 * @author felix
 * Führt mit Hilfe der Eventful-Java Api einen Lookups bei Eventful durch
 */
public class EventFulLookup extends Lookup {

	private static final String key = "xKxMczSsF8MDk5TF";
	
	public List<StandartEvent> lookup(String query, int limit)  {
		
		APIConfiguration.setEvdbUser("Kiechlus");
		APIConfiguration.setEvdbPassword("eventsearch");
		APIConfiguration.setApiKey(key);
		
		EventSearchRequest req = new EventSearchRequest();
		req.setPageSize(limit);
		req.setKeywords(query);
		EventOperations op = new EventOperations();
		com.evdb.javaapi.data.SearchResult result = null;
		try {
			result = op.search(req);
		} catch (EVDBRuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (EVDBAPIException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		List<com.evdb.javaapi.data.Event> eventfulListe = result.getEvents();
		List<StandartEvent> liste = new LinkedList<StandartEvent>();
		
		for(com.evdb.javaapi.data.Event event : eventfulListe){
			StandartEvent endev = new StandartEvent(event);
			liste.add(endev);
		}
		return liste;	
	}

}
